add another example
authorHavoc Pennington <hp@pobox.com>
Wed, 12 Dec 2001 06:40:08 +0000 (06:40 +0000)
committerHavoc Pennington <hp@src.gnome.org>
Wed, 12 Dec 2001 06:40:08 +0000 (06:40 +0000)
2001-12-12  Havoc Pennington  <hp@pobox.com>

* gtk/text_widget.sgml: add another example

docs/reference/ChangeLog
docs/reference/gtk/text_widget.sgml

index 74771db9494ab58ded29701520d43d8c6f314527..40434b6bd83a16e57e3733314c10150135075a53 100644 (file)
@@ -1,3 +1,7 @@
+2001-12-12  Havoc Pennington  <hp@pobox.com>
+
+       * gtk/text_widget.sgml: add another example
+
 2001-12-09  Matthias Clasen  <matthiasc@poet.de>
 
        * gtk/tmpl/gtkmain.sgml: Markup fixes.
index 42d5525e2912518f647fff6f20f0f62ade8ba2d4..3c785254a3d61408fb5b2d489ad0bdb2357b2a95 100644 (file)
@@ -127,7 +127,7 @@ might look like this:
 
   buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
 
-  gtk_text_buffer_set_text (buffer, "Hello, this is some text");
+  gtk_text_buffer_set_text (buffer, "Hello, this is some text", -1);
 
   /* Now you might put the view in a container and display it on the
    * screen; when the user edits the text, signals on the buffer
@@ -143,4 +143,68 @@ gtk_text_view_set_buffer().
 
 </refsect1>
 
+<refsect1>
+<title>Example of Changing Text Attributes</title>
+
+<para>
+
+There are two ways to affect text attributes in 
+<link linkend="GtkTextView">GtkTextView</link>.
+You can change the default attributes for a given 
+<link linkend="GtkTextView">GtkTextView</link>, and you can 
+apply tags that change the attributes for a region of text.
+For text features that come from the theme &mdash; such as 
+font and foreground color &mdash use standard 
+<link linkend="GtkWidget">GtkWidget</link>
+functions such as 
+<link linkend="gtk_widget_modify_font">gtk_widget_modify_font()</link>
+or 
+<link linkend="gtk_widget_modify_fg">gtk_widget_modify_fg()</link>.
+For other attributes there are dedicated methods on 
+<link linkend="GtkTextView">GtkTextView</link> such as 
+<link linkend="gtk_text_view_set_tabs">gtk_text_view_set_tabs()</link>.
+
+<programlisting>
+  GtkWidget *view;
+  GtkTextBuffer *buffer;
+  PangoFontDescription *font_desc;
+  GdkColor color;
+  GtkTextTag *tag;
+
+  view = gtk_text_view_new ();
+
+  buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
+
+  gtk_text_buffer_set_text (buffer, "Hello, this is some text", -1);
+
+  /* Change default font throughout the widget */
+  font_desc = pango_font_description_from_string ("Serif 15");
+  gtk_widget_modify_font (view, font_desc);
+  pango_font_description_free (font_desc);
+
+  /* Change default color throughout the widget */
+  gdk_color_parse ("green", &color);
+  gtk_widget_modify_fg (view, GTK_STATE_NORMAL, &color);
+
+  /* Change left margin throughout the widget */
+  gtk_text_view_set_left_margin (GTK_TEXT_VIEW (view), 30);
+
+  /* Use a tag to change the color for just one part of the widget */
+  tag = gtk_text_buffer_create_tag (buffer, "blue_foreground",
+                                   "foreground", "blue", NULL);  
+  gtk_text_buffer_get_iter_at_offset (buffer, &start, 7);
+  gtk_text_buffer_get_iter_at_offset (buffer, &end, 12);
+  gtk_text_buffer_apply_tag (buffer, tag, &start, &end);
+</programlisting>
+
+</para>
+
+<para>
+The <application>gtk-demo</application> application that comes with
+GTK+ contains more example code for <link
+linkend="GtkTextView">GtkTextView</link>.
+</para>
+
+</refsect1>
+
 </refentry>